@tool
class_name DamageSender
extends Area2D



@export var damage_info: DamageInfo = null
@export var disabled: bool = false:
    set(value):
        disabled = value
        for child in get_children():
            if child is CollisionShape2D or child is CollisionPolygon2D:
                # child.disabled = disabled
                child.set_deferred("disabled", disabled)


## 在DamageReceiver中调用DamageSysytem处理完DamageInfo后触发该信号
@warning_ignore("unused_signal")
signal hit(info: DamageInfo, position: Vector2)


# 设置节点配置警告，脚本需是工具脚本
func _get_configuration_warnings() -> PackedStringArray:
    var warnings = PackedStringArray()

    # if get_scene_file_path() == "":
    #     warnings.append("请从保存的场景实例化该节点，以确保正常工作")

    for child in get_children():
        if child is not CollisionShape2D:
            warnings.append("请使用CollisionShape2D作为子节点，以确保能可以正确获取击中的位置")
            break

    return warnings


func get_collision_shape(idx: int = 0) -> CollisionShape2D:
    return get_child(idx)


func get_collision_shapes() -> Array[CollisionShape2D]:
    var list: Array[CollisionShape2D] = []
    for child in get_children():
        if child is not CollisionShape2D: continue
        list.append(child)
    return list
